package com.dtagri.fjwlw.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.base.BaseActivity;
import com.dtagri.fjwlw.base.BaseFragment;

/**
 * 简单Activity
 * 
 * @author wxjn
 * 
 */
public class ZSimpleBackActivity extends BaseActivity {
	public final static String BUNDLE_KEY_PAGE = "BUNDLE_KEY_PAGE";
	private Fragment fragment;

	@Override
	public void initView() {
		int mPageValue = getIntent().getIntExtra(BUNDLE_KEY_PAGE, 0);
		ZSimpleBackPage page = ZSimpleBackPage.getPageByValue(mPageValue);
		setActionBarTitle(page.getTitle());
	}

	@Override
	protected void init(Bundle savedInstanceState) {
		super.init(savedInstanceState);
		if (savedInstanceState == null) {
			fragment = getFragment();
			getSupportFragmentManager().beginTransaction()
					.add(R.id.container, fragment).commit();
		}
	}

	@Override
	protected boolean hasBackButton() {
		return true;
	}

	@Override
	protected int getLayoutId() {
		return R.layout.layout_simple_framelayout;
	}

	private Fragment getFragment() {
		int mPageValue = getIntent().getIntExtra(BUNDLE_KEY_PAGE, 0);
		ZSimpleBackPage page = ZSimpleBackPage.getPageByValue(mPageValue);

		BaseFragment fragment = null;
		try {
			fragment = (BaseFragment) page.getClz().newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fragment;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub

	}
}
